'use strict';

const getOrders = require('./get-orders');
const getOrderDetail = require('./get-order-detail');
const createOrder = require('./create-order');
const cancelOrder = require('./cancel-order');
const updateOrderStatus = require('./update-order-status');
const submitRating = require('./submit-rating');

exports.main = async (event, context) => {
  const { action, data } = event;
  
  try {
    switch (action) {
      case 'get-orders':
        return await getOrders.main(event, context);
      case 'get-order-detail':
        return await getOrderDetail.main(event, context);
      case 'create-order':
        return await createOrder.main(event, context);
      case 'cancel-order':
        return await cancelOrder.main(event, context);
      case 'update-order-status':
        return await updateOrderStatus.main(event, context);
      case 'submit-rating':
        return await submitRating.main(event, context);
      default:
        return {
          code: 400,
          message: '未知的操作类型',
          data: null
        };
    }
  } catch (error) {
    return {
      code: 500,
      message: '服务器内部错误',
      data: null
    };
  }
};
